package com.wps.wdztv6.controller;

import com.alibaba.fastjson2.JSON;
import com.wps.wdztv6.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserInfoService userInfoService;

    @RequestMapping("/{id}")
    public void avatar(
            @PathVariable("id") String id,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws IOException {
        Map<String, String[]> queryMap = request.getParameterMap();
        log.info("/user/id PathVariable:{}", id);
        log.info("/v1/3rd/file/info queryMap:{}", JSON.toJSONString(queryMap));
        response.setContentType(MediaType.IMAGE_PNG_VALUE);
        userInfoService.outputUserAvatar(id, response.getOutputStream());
    }


}
